//
//  MineHeaderView.m
//  OneCreditTreasure
//
//  Created by iOS Tedu on 16/8/25.
//
//

#import "MineHeaderView.h"

@interface MineHeaderView ()
@property (nonatomic, strong) UIView *lineView;
@property (nonatomic, strong) UIView *lineView1;
@property (nonatomic, strong) UIView *lineView2;
@property (nonatomic, strong) UIView *profitView;
@property (nonatomic, strong) UIView *balanceView;
@property (nonatomic, strong) UIView *assetView;
@property (nonatomic, strong) UIButton *unLoginBtn;

@property (nonatomic, getter=isLogin) BOOL login;
@end

@implementation MineHeaderView
#pragma mark - 生命周期 life cycle
- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        if ([[NSUserDefaults standardUserDefaults] boolForKey:@"Login"]) {
            [self balanceView];
            [self lineView];
            [self profitView];
            [self assetView];
        } else {
            [self unLoginBtn];
        }
    }
    return self;
}

#pragma mark - 方法 methods
- (void)goToLogin:sender {
    if ([self.delegate respondsToSelector:@selector(goToLogin:)]) {
        [self.delegate goToLogin:sender];
    }
}

- (void)getMoney:sender {
    if ([self.delegate respondsToSelector:@selector(getMoney:)]) {
        [self.delegate getMoney:sender];
    }
}

- (void)recharge:sender {
    if ([self.delegate respondsToSelector:@selector(recharge:)]) {
        [self.delegate recharge:sender];
    }
}

#pragma mark - 懒加载 lazy loading
- (UIView *)profitView {
    if(_profitView == nil) {
        //显示收益的View
        _profitView = [[UIView alloc] init];
        CGFloat profitViewWidth = kScreenW / 2 - 1;
        _profitView.backgroundColor = [UIColor whiteColor];
        [self addSubview:_profitView];
        CGFloat profitHeight = 50 * AUTO_WIDTH;
        [_profitView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(0);
            make.bottom.equalTo(self.lineView2.mas_top).equalTo(0);
            make.width.equalTo(profitViewWidth);
            make.height.equalTo(profitHeight);
        }];
        
        UILabel *profitTipLB = [UILabel new];
        [profitTipLB setText:@"累计收益 (元)"];
        profitTipLB.font = [UIFont systemFontOfSize:15 * AUTO_WIDTH];
        [_profitView addSubview:profitTipLB];
        CGFloat profitLBWidth = kScreenW / 4;
        CGFloat profitTipLBHeight = 20  * AUTO_WIDTH;
        [profitTipLB mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.equalTo(profitLBWidth);
            make.left.top.equalTo(4);
            make.height.equalTo(profitTipLBHeight);
        }];
        
        UILabel *profitLB = [UILabel new];
        [profitLB setText:@"0.00"];
        profitLB.textAlignment = NSTextAlignmentRight;
        profitLB.font = [UIFont boldSystemFontOfSize:22 * AUTO_WIDTH];
        [_profitView addSubview:profitLB];
        CGFloat profitLBHeight = 25 * AUTO_WIDTH;
        [profitLB mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(profitTipLB.mas_right).equalTo(0);
            make.bottom.equalTo(-5);
            make.right.equalTo(-15);
            make.height.equalTo(profitLBHeight);
        }];
    }
    return _profitView;
}

- (UIView *)balanceView {
    if(_balanceView == nil) {
        _balanceView = [[UIView alloc] init];
        CGFloat balanceViewWidth = kScreenW / 2;
        [self addSubview:_balanceView];
        CGFloat balanceHeight = 50 * AUTO_WIDTH;
        [_balanceView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(0);
            make.bottom.equalTo(self.lineView2.mas_top).equalTo(0);
            make.height.equalTo(balanceHeight);
            make.width.equalTo(balanceViewWidth);
        }];
        _balanceView.backgroundColor = [UIColor whiteColor];
        
        UILabel *balanceTipLB = [UILabel new];
        [balanceTipLB setText:@"余额 (元)"];
        balanceTipLB.font = [UIFont systemFontOfSize:15 * AUTO_WIDTH];
        [_balanceView addSubview:balanceTipLB];
        CGFloat balanceLBWidth = balanceViewWidth / 2;
        CGFloat balanceTipLBHeight = balanceHeight * 2 / 5 * AUTO_WIDTH;
        [balanceTipLB mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.equalTo(4);
            make.width.equalTo(balanceLBWidth);
            make.height.equalTo(balanceTipLBHeight);
        }];
        
        UILabel *balanceLB = [UILabel new];
        balanceLB.font = [UIFont boldSystemFontOfSize:22];
        [balanceLB setText:@"0.00"];
        balanceLB.textAlignment = NSTextAlignmentRight;
        [_balanceView addSubview:balanceLB];
        CGFloat balanceLBHeight = 25 * AUTO_WIDTH;
        [balanceLB mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(-5);
            make.right.equalTo(-15);
            make.left.equalTo(balanceTipLB.mas_right).equalTo(0);
            make.height.equalTo(balanceLBHeight);
        }];
    }
    return _balanceView;
}

- (UIView *)assetView {
    if(_assetView == nil) {
        //显示我的总资产的View
        _assetView = [UIView new];
        _assetView.backgroundColor = [UIColor whiteColor];
        [self addSubview:_assetView];
        [_assetView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.right.equalTo(0);
            make.bottom.equalTo(self.lineView1.mas_top).equalTo(0);
        }];
        
        UILabel *assetTipLB = [UILabel new];
        assetTipLB.text = @"我的总资产 (元)";
        [_assetView addSubview:assetTipLB];
        CGFloat assetTipLBWidth = kScreenW / 3;
        CGFloat assetTipLBHeight = 20 * AUTO_WIDTH;
        [assetTipLB mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.equalTo(8);
            make.width.equalTo(assetTipLBWidth);
            make.height.equalTo(assetTipLBHeight);
        }];
        assetTipLB.font = [UIFont systemFontOfSize:17 * AUTO_WIDTH];
        
        UILabel *assetLB = [UILabel new];
        assetLB.font = [UIFont boldSystemFontOfSize:25 * AUTO_WIDTH];
        assetLB.text = @"0.00";
        [_assetView addSubview:assetLB];
        [assetLB mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(0);
            make.centerY.equalTo(-10);
        }];
        
        CGFloat btnLeftWidth = 120 * AUTO_WIDTH;
        UIButton *getMoneyBtn = [UIButton buttonWithType:UIButtonTypeSystem];
        [getMoneyBtn setTintColor:[UIColor blackColor]];
        [_assetView addSubview:getMoneyBtn];
        [getMoneyBtn setTitle:@"提现" forState:UIControlStateNormal];
        CGFloat btnWidth = 70 * AUTO_WIDTH;
        CGFloat btnHeight = 35 * AUTO_WIDTH;
        [getMoneyBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(btnLeftWidth);
            make.bottom.equalTo(-20);
            make.height.equalTo(btnHeight);
            make.width.equalTo(btnWidth);
        }];
        getMoneyBtn.layer.cornerRadius = 6;
        getMoneyBtn.layer.borderWidth = 1;
        getMoneyBtn.layer.borderColor = [[UIColor blackColor] CGColor];
        [getMoneyBtn addTarget:self action:@selector(getMoney:) forControlEvents:UIControlEventTouchUpInside];
        
        UIButton *rechargeBtn = [UIButton buttonWithType:UIButtonTypeSystem];
        [rechargeBtn setTintColor:[UIColor blackColor]];
        [_assetView addSubview:rechargeBtn];
        [rechargeBtn setTitle:@"充值" forState:UIControlStateNormal];
        [rechargeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(getMoneyBtn.mas_right).equalTo(10);
            make.bottom.equalTo(-20);
            make.height.equalTo(btnHeight);
            make.width.equalTo(btnWidth);
        }];
        rechargeBtn.layer.cornerRadius = 6;
        rechargeBtn.layer.borderWidth = 1;
        rechargeBtn.layer.borderColor = [[UIColor blackColor] CGColor];
        [rechargeBtn addTarget:self action:@selector(recharge:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _assetView;
}

- (UIView *)lineView {
    if(_lineView == nil) {
        _lineView = [[UIView alloc] init];
        _lineView.backgroundColor = [UIColor lightGrayColor];
        [self addSubview:_lineView];
        [_lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.balanceView.mas_right).equalTo(0);
            make.bottom.equalTo(0);
            make.height.equalTo(51);
            make.width.equalTo(1);
        }];
    }
    return _lineView;
}

- (UIView *)lineView1 {
    if(_lineView1 == nil) {
        _lineView1 = [[UIView alloc] init];
        _lineView1.backgroundColor = [UIColor lightGrayColor];
        [self addSubview:_lineView1];
        [_lineView1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self.balanceView.mas_top).equalTo(0);
            make.left.right.equalTo(0);
            make.height.equalTo(1);
        }];
    }
    return _lineView1;
}

- (UIView *)lineView2 {
    if(_lineView2 == nil) {
        _lineView2 = [[UIView alloc] init];
        _lineView2.backgroundColor = [UIColor lightGrayColor];
        [self addSubview:_lineView2];
        [_lineView2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.equalTo(0);
            make.height.equalTo(1);
        }];
    }
    return _lineView2;
}

- (UIButton *)unLoginBtn {
    if(_unLoginBtn == nil) {
        _unLoginBtn = [UIButton buttonWithType:UIButtonTypeSystem];
        [self addSubview:_unLoginBtn];
        [_unLoginBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(0);
        }];
        _unLoginBtn.tintColor = [UIColor blackColor];
        [_unLoginBtn setTitle:@"您还未登陆,点击登陆" forState:UIControlStateNormal];
        [_unLoginBtn addTarget:self action:@selector(goToLogin:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _unLoginBtn;
}

@end
